home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / doom / knbot03.zip / SRC.ZIP / WEAPONS.QC < prev    next >
Text File  |  1997-03-12  |  26KB  |  1,254 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9. // called by worldspawn
  10. void() W_Precache =
  11. {
  12.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  13.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  14.     precache_sound ("weapons/sgun1.wav");
  15.     precache_sound ("weapons/guncock.wav");    // player shotgun
  16.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  17.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/spike2.wav");    // super spikes
  20.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  21.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  22.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  23.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  24. };
  25.  
  26. float() crandom =
  27. {
  28.     return 2*(random() - 0.5);
  29. };
  30.  
  31. /*
  32. ================
  33. W_FireAxe
  34. ================
  35. */
  36. void() W_FireAxe =
  37. {
  38.     local    vector    source;
  39.     local    vector    org;
  40.  
  41.     source = self.origin + '0 0 16';
  42.     traceline (source, source + v_forward*64, FALSE, self);
  43.     if (trace_fraction == 1.0)
  44.         return;
  45.     
  46.     org = trace_endpos - v_forward*4;
  47.  
  48.     if (trace_ent.takedamage)
  49.     {
  50.         trace_ent.axhitme = 1;
  51.         SpawnBlood (org, '0 0 0', 20);
  52.         T_Damage (trace_ent, self, self, 20);
  53.     }
  54.     else
  55.     {    // hit wall
  56.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  57.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  58.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  59.         WriteCoord (MSG_BROADCAST, org_x);
  60.         WriteCoord (MSG_BROADCAST, org_y);
  61.         WriteCoord (MSG_BROADCAST, org_z);
  62.     }
  63. };
  64.  
  65.  
  66. //============================================================================
  67.  
  68.  
  69. vector() wall_velocity =
  70. {
  71.     local vector    vel;
  72.     
  73.     vel = normalize (self.velocity);
  74.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  75.     vel = vel + 2*trace_plane_normal;
  76.     vel = vel * 200;
  77.     
  78.     return vel;
  79. };
  80.  
  81.  
  82. /*
  83. ================
  84. SpawnMeatSpray
  85. ================
  86. */
  87. void(vector org, vector vel) SpawnMeatSpray =
  88. {
  89.     local    entity missile, mpuff;
  90.     local    vector    org;
  91.  
  92.     missile = spawn ();
  93.     missile.owner = self;
  94.     missile.movetype = MOVETYPE_BOUNCE;
  95.     missile.solid = SOLID_NOT;
  96.  
  97.     makevectors (self.angles);
  98.  
  99.     missile.velocity = vel;
  100.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  101.  
  102.     missile.avelocity = '3000 1000 2000';
  103.     
  104. // set missile duration
  105.     missile.nextthink = time + 1;
  106.     missile.think = SUB_Remove;
  107.  
  108.     setmodel (missile, "progs/zom_gib.mdl");
  109.     setsize (missile, '0 0 0', '0 0 0');        
  110.     setorigin (missile, org);
  111. };
  112.  
  113. /*
  114. ================
  115. SpawnBlood
  116. ================
  117. */
  118. void(vector org, vector vel, float damage) SpawnBlood =
  119. {
  120.     particle (org, vel*0.1, 73, damage*2);
  121. };
  122.  
  123. /*
  124. ================
  125. spawn_touchblood
  126. ================
  127. */
  128. void(float damage) spawn_touchblood =
  129. {
  130.     local vector    vel;
  131.  
  132.     vel = wall_velocity () * 0.2;
  133.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  134. };
  135.  
  136.  
  137. /*
  138. ================
  139. SpawnChunk
  140. ================
  141. */
  142. void(vector org, vector vel) SpawnChunk =
  143. {
  144.     particle (org, vel*0.02, 0, 10);
  145. };
  146.  
  147. /*
  148. ==============================================================================
  149.  
  150. MULTI-DAMAGE
  151.  
  152. Collects multiple small damages into a single damage
  153.  
  154. ==============================================================================
  155. */
  156.  
  157. entity    multi_ent;
  158. float    multi_damage;
  159.  
  160. void() ClearMultiDamage =
  161. {
  162.     multi_ent = world;
  163.     multi_damage = 0;
  164. };
  165.  
  166. void() ApplyMultiDamage =
  167. {
  168.     if (!multi_ent)
  169.         return;
  170.     T_Damage (multi_ent, self, self, multi_damage);
  171. };
  172.  
  173. void(entity hit, float damage) AddMultiDamage =
  174. {
  175.     if (!hit)
  176.         return;
  177.     
  178.     if (hit != multi_ent)
  179.     {
  180.         ApplyMultiDamage ();
  181.         multi_damage = damage;
  182.         multi_ent = hit;
  183.     }
  184.     else
  185.         multi_damage = multi_damage + damage;
  186. };
  187.  
  188. /*
  189. ==============================================================================
  190.  
  191. BULLETS
  192.  
  193. ==============================================================================
  194. */
  195.  
  196. /*
  197. ================
  198. TraceAttack
  199. ================
  200. */
  201. void(float damage, vector dir) TraceAttack =
  202. {
  203.     local    vector    vel, org;
  204.     
  205.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  206.     vel = vel + 2*trace_plane_normal;
  207.     vel = vel * 200;
  208.  
  209.     org = trace_endpos - dir*4;
  210.  
  211.     if (trace_ent.takedamage)
  212.     {
  213.         SpawnBlood (org, vel*0.2, damage);
  214.         AddMultiDamage (trace_ent, damage);
  215.     }
  216.     else
  217.     {
  218.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  219.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  220.         WriteCoord (MSG_BROADCAST, org_x);
  221.         WriteCoord (MSG_BROADCAST, org_y);
  222.         WriteCoord (MSG_BROADCAST, org_z);
  223.     }
  224. };
  225.  
  226. /*
  227. ================
  228. FireBullets
  229.  
  230. Used by shotgun, super shotgun, and enemy soldier firing
  231. Go to the trouble of combining multiple pellets into a single damage call.
  232. ================
  233. */
  234. void(float shotcount, vector dir, vector spread) FireBullets =
  235. {
  236.     local    vector direction;
  237.     local    vector    src;
  238.     
  239.     makevectors(self.v_angle);
  240.  
  241.     src = self.origin + v_forward*10;
  242.     src_z = self.absmin_z + self.size_z * 0.7;
  243.  
  244.     ClearMultiDamage ();
  245.     while (shotcount > 0)
  246.     {
  247.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  248.  
  249.         traceline (src, src + direction*2048, FALSE, self);
  250.         if (trace_fraction != 1.0)
  251.             TraceAttack (4, direction);
  252.  
  253.         shotcount = shotcount - 1;
  254.     }
  255.     ApplyMultiDamage ();
  256. };
  257.  
  258. /*
  259. ================
  260. W_FireShotgun
  261. ================
  262. */
  263. void() W_FireShotgun =
  264. {
  265.     local vector dir;
  266.  
  267.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  268.  
  269.     self.punchangle_x = -2;
  270.     
  271.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  272.     dir = aim (self, 100000);
  273.     FireBullets (6, dir, '0.04 0.04 0');
  274. };
  275.  
  276.  
  277. /*
  278. ================
  279. W_FireSuperShotgun
  280. ================
  281. */
  282. void() W_FireSuperShotgun =
  283. {
  284.     local vector dir;
  285.  
  286.     if (self.currentammo == 1)
  287.     {
  288.         W_FireShotgun ();
  289.         return;
  290.     }
  291.         
  292.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  293.  
  294.     self.punchangle_x = -4;
  295.     
  296.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  297.     dir = aim (self, 100000);
  298.     FireBullets (14, dir, '0.14 0.08 0');
  299. };
  300.  
  301.  
  302. /*
  303. ==============================================================================
  304.  
  305. ROCKETS
  306.  
  307. ==============================================================================
  308. */
  309.  
  310. void()    s_explode1    =    [0,        s_explode2] {};
  311. void()    s_explode2    =    [1,        s_explode3] {};
  312. void()    s_explode3    =    [2,        s_explode4] {};
  313. void()    s_explode4    =    [3,        s_explode5] {};
  314. void()    s_explode5    =    [4,        s_explode6] {};
  315. void()    s_explode6    =    [5,        SUB_Remove] {};
  316.  
  317. void() BecomeExplosion =
  318. {
  319.     self.movetype = MOVETYPE_NONE;
  320.     self.velocity = '0 0 0';
  321.     self.touch = SUB_Null;
  322.     setmodel (self, "progs/s_explod.spr");
  323.     self.solid = SOLID_NOT;
  324.     s_explode1 ();
  325. };
  326.  
  327. void() T_MissileTouch =
  328. {
  329.     local float    damg;
  330.  
  331.     if (other == self.owner)
  332.         return;        // don't explode on owner
  333.  
  334.     if (pointcontents(self.origin) == CONTENT_SKY)
  335.     {
  336.         remove(self);
  337.         return;
  338.     }
  339.  
  340.     damg = 100 + random()*20;
  341.     
  342.     if (other.health)
  343.     {
  344.         if (other.classname == "monster_shambler")
  345.             damg = damg * 0.5;    // mostly immune
  346.         T_Damage (other, self, self.owner, damg );
  347.     }
  348.  
  349.     // don't do radius damage to the other, because all the damage
  350.     // was done in the impact
  351.     T_RadiusDamage (self, self.owner, 120, other);
  352.  
  353. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  354.     self.origin = self.origin - 8*normalize(self.velocity);
  355.  
  356.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  357.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  358.     WriteCoord (MSG_BROADCAST, self.origin_x);
  359.     WriteCoord (MSG_BROADCAST, self.origin_y);
  360.     WriteCoord (MSG_BROADCAST, self.origin_z);
  361.  
  362.     BecomeExplosion ();
  363. };
  364.  
  365.  
  366.  
  367. /*
  368. ================
  369. W_FireRocket
  370. ================
  371. */
  372. void() W_FireRocket =
  373. {
  374.     local    entity missile, mpuff;
  375.     
  376.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  377.     
  378.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  379.  
  380.     self.punchangle_x = -2;
  381.  
  382.     missile = spawn ();
  383.     missile.owner = self;
  384.     missile.movetype = MOVETYPE_FLYMISSILE;
  385.     missile.solid = SOLID_BBOX;
  386.         
  387. // set missile speed    
  388.  
  389.     makevectors (self.v_angle);
  390.     missile.velocity = aim(self, 1000);
  391.     missile.velocity = missile.velocity * 1000;
  392.     missile.angles = vectoangles(missile.velocity);
  393.     
  394.     missile.touch = T_MissileTouch;
  395.     
  396. // set missile duration
  397.     missile.nextthink = time + 5;
  398.     missile.think = SUB_Remove;
  399.  
  400.     setmodel (missile, "progs/missile.mdl");
  401.     setsize (missile, '0 0 0', '0 0 0');        
  402.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  403. };
  404.  
  405. /*
  406. ===============================================================================
  407.  
  408. LIGHTNING
  409.  
  410. ===============================================================================
  411. */
  412.  
  413. /*
  414. =================
  415. LightningDamage
  416. =================
  417. */
  418. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  419. {
  420.     local entity        e1, e2;
  421.     local vector        f;
  422.     
  423.     f = p2 - p1;
  424.     normalize (f);
  425.     f_x = 0 - f_y;
  426.     f_y = f_x;
  427.     f_z = 0;
  428.     f = f*16;
  429.  
  430.     e1 = e2 = world;
  431.  
  432.     traceline (p1, p2, FALSE, self);
  433.     if (trace_ent.takedamage)
  434.     {
  435.         particle (trace_endpos, '0 0 100', 225, damage*4);
  436.         T_Damage (trace_ent, from, from, damage);
  437.         if (self.classname == "player")
  438.         {
  439.             if (other.classname == "player")
  440.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  441.         }
  442.     }
  443.     e1 = trace_ent;
  444.  
  445.     traceline (p1 + f, p2 + f, FALSE, self);
  446.     if (trace_ent != e1 && trace_ent.takedamage)
  447.     {
  448.         particle (trace_endpos, '0 0 100', 225, damage*4);
  449.         T_Damage (trace_ent, from, from, damage);
  450.     }
  451.     e2 = trace_ent;
  452.  
  453.     traceline (p1 - f, p2 - f, FALSE, self);
  454.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  455.     {
  456.         particle (trace_endpos, '0 0 100', 225, damage*4);
  457.         T_Damage (trace_ent, from, from, damage);
  458.     }
  459. };
  460.  
  461.  
  462. void() W_FireLightning =
  463. {
  464.     local    vector        org;
  465.  
  466.     if (self.ammo_cells < 1)
  467.     {
  468.         self.weapon = W_BestWeapon ();
  469.         W_SetCurrentAmmo ();
  470.         return;
  471.     }
  472.  
  473. // explode if under water
  474.     if (self.waterlevel > 1)
  475.     {
  476.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  477.         self.ammo_cells = 0;
  478.         W_SetCurrentAmmo ();
  479.         return;
  480.     }
  481.  
  482.     if (self.t_width < time)
  483.     {
  484.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  485.         self.t_width = time + 0.6;
  486.     }
  487.     self.punchangle_x = -2;
  488.  
  489.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  490.  
  491.     org = self.origin + '0 0 16';
  492.     
  493.     traceline (org, org + v_forward*600, TRUE, self);
  494.  
  495.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  496.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  497.     WriteEntity (MSG_BROADCAST, self);
  498.     WriteCoord (MSG_BROADCAST, org_x);
  499.     WriteCoord (MSG_BROADCAST, org_y);
  500.     WriteCoord (MSG_BROADCAST, org_z);
  501.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  502.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  503.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  504.  
  505.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  506. };
  507.  
  508.  
  509. //=============================================================================
  510.  
  511.  
  512. void() GrenadeExplode =
  513. {
  514.     T_RadiusDamage (self, self.owner, 120, world);
  515.  
  516.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  517.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  518.     WriteCoord (MSG_BROADCAST, self.origin_x);
  519.     WriteCoord (MSG_BROADCAST, self.origin_y);
  520.     WriteCoord (MSG_BROADCAST, self.origin_z);
  521.  
  522.     BecomeExplosion ();
  523. };
  524.  
  525. void() GrenadeTouch =
  526. {
  527.     if (other == self.owner)
  528.         return;        // don't explode on owner
  529.     if (other.takedamage == DAMAGE_AIM)
  530.     {
  531.         GrenadeExplode();
  532.         return;
  533.     }
  534.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  535.     if (self.velocity == '0 0 0')
  536.         self.avelocity = '0 0 0';
  537. };
  538.  
  539. /*
  540. ================
  541. W_FireGrenade
  542. ================
  543. */
  544. void() W_FireGrenade =
  545. {
  546.     local    entity missile, mpuff;
  547.     
  548.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  549.     
  550.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  551.  
  552.     self.punchangle_x = -2;
  553.  
  554.     missile = spawn ();
  555.     missile.owner = self;
  556.     missile.movetype = MOVETYPE_BOUNCE;
  557.     missile.solid = SOLID_BBOX;
  558.     missile.classname = "grenade";
  559.         
  560. // set missile speed    
  561.  
  562.     makevectors (self.v_angle);
  563.  
  564.     if (self.v_angle_x)
  565.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  566.     else
  567.     {
  568.         missile.velocity = aim(self, 10000);
  569.         missile.velocity = missile.velocity * 600;
  570.         missile.velocity_z = 200;
  571.     }
  572.  
  573.     missile.avelocity = '300 300 300';
  574.  
  575.     missile.angles = vectoangles(missile.velocity);
  576.     
  577.     missile.touch = GrenadeTouch;
  578.     
  579. // set missile duration
  580.     missile.nextthink = time + 2.5;
  581.     missile.think = GrenadeExplode;
  582.  
  583.     setmodel (missile, "progs/grenade.mdl");
  584.     setsize (missile, '0 0 0', '0 0 0');        
  585.     setorigin (missile, self.origin);
  586. };
  587.  
  588.  
  589. //=============================================================================
  590.  
  591. void() spike_touch;
  592. void() superspike_touch;
  593.  
  594.  
  595. /*
  596. ===============
  597. launch_spike
  598.  
  599. Used for both the player and the ogre
  600. ===============
  601. */
  602. void(vector org, vector dir) launch_spike =
  603. {
  604.     newmis = spawn ();
  605.     newmis.owner = self;
  606.     newmis.movetype = MOVETYPE_FLYMISSILE;
  607.     newmis.solid = SOLID_BBOX;
  608.  
  609.     newmis.angles = vectoangles(dir);
  610.     
  611.     newmis.touch = spike_touch;
  612.     newmis.classname = "spike";
  613.     newmis.think = SUB_Remove;
  614.     newmis.nextthink = time + 6;
  615.         setmodel (newmis, "progs/spike.mdl"); // was spike.mdl
  616.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  617.     setorigin (newmis, org);
  618.  
  619.     newmis.velocity = dir * 1000;
  620.         //newmis.angles = '0 0 180';
  621. };
  622.  
  623. void() W_FireSuperSpikes =
  624. {
  625.     local vector    dir;
  626.     local entity    old;
  627.     
  628.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  629.     self.attack_finished = time + 0.2;
  630.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  631.     dir = aim (self, 1000);
  632.     launch_spike (self.origin + '0 0 16', dir);
  633.     newmis.touch = superspike_touch;
  634.     setmodel (newmis, "progs/s_spike.mdl");
  635.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  636.     self.punchangle_x = -2;
  637. };
  638.  
  639. void(float ox) W_FireSpikes =
  640. {
  641.     local vector    dir;
  642.     local entity    old;
  643.     
  644.     makevectors (self.v_angle);
  645.     
  646.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  647.     {
  648.         W_FireSuperSpikes ();
  649.         return;
  650.     }
  651.  
  652.     if (self.ammo_nails < 1)
  653.     {
  654.         self.weapon = W_BestWeapon ();
  655.         W_SetCurrentAmmo ();
  656.         return;
  657.     }
  658.  
  659.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  660.     self.attack_finished = time + 0.2;
  661.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  662.     dir = aim (self, 1000);
  663.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  664.  
  665.     self.punchangle_x = -2;
  666. };
  667.  
  668.  
  669.  
  670. .float hit_z;
  671. void() spike_touch =
  672. {
  673. local float rand;
  674.     if (other == self.owner)
  675.         return;
  676.  
  677.     if (other.solid == SOLID_TRIGGER)
  678.         return;    // trigger field, do nothing
  679.  
  680.     if (pointcontents(self.origin) == CONTENT_SKY)
  681.     {
  682.         remove(self);
  683.         return;
  684.     }
  685.     
  686. // hit something that bleeds
  687.     if (other.takedamage)
  688.     {
  689.         spawn_touchblood (9);
  690.         T_Damage (other, self, self.owner, 9);
  691.     }
  692.     else
  693.     {
  694.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  695.         
  696.         if (self.classname == "wizspike")
  697.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  698.         else if (self.classname == "knightspike")
  699.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  700.         else
  701.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  702.         WriteCoord (MSG_BROADCAST, self.origin_x);
  703.         WriteCoord (MSG_BROADCAST, self.origin_y);
  704.         WriteCoord (MSG_BROADCAST, self.origin_z);
  705.     }
  706.  
  707.     remove(self);
  708.  
  709. };
  710.  
  711. void() superspike_touch =
  712. {
  713. local float rand;
  714.     if (other == self.owner)
  715.         return;
  716.  
  717.     if (other.solid == SOLID_TRIGGER)
  718.         return;    // trigger field, do nothing
  719.  
  720.     if (pointcontents(self.origin) == CONTENT_SKY)
  721.     {
  722.         remove(self);
  723.         return;
  724.     }
  725.     
  726. // hit something that bleeds
  727.     if (other.takedamage)
  728.     {
  729.         spawn_touchblood (18);
  730.         T_Damage (other, self, self.owner, 18);
  731.     }
  732.     else
  733.     {
  734.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  735.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  736.         WriteCoord (MSG_BROADCAST, self.origin_x);
  737.         WriteCoord (MSG_BROADCAST, self.origin_y);
  738.         WriteCoord (MSG_BROADCAST, self.origin_z);
  739.     }
  740.  
  741.     remove(self);
  742.  
  743. };
  744.  
  745.  
  746. /*
  747. ===============================================================================
  748.  
  749. PLAYER WEAPON USE
  750.  
  751. ===============================================================================
  752. */
  753.  
  754. void() W_SetCurrentAmmo =
  755. {
  756.     player_run ();        // get out of any weapon firing states
  757.  
  758.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  759.     
  760.     if (self.weapon == IT_AXE)
  761.     {
  762.         self.currentammo = 0;
  763.         self.weaponmodel = "progs/v_axe.mdl";
  764.         self.weaponframe = 0;
  765.     }
  766.     else if (self.weapon == IT_SHOTGUN)
  767.     {
  768.         self.currentammo = self.ammo_shells;
  769.         self.weaponmodel = "progs/v_shot.mdl";
  770.         self.weaponframe = 0;
  771.         self.items = self.items | IT_SHELLS;
  772.     }
  773.     else if (self.weapon == IT_SUPER_SHOTGUN)
  774.     {
  775.         self.currentammo = self.ammo_shells;
  776.         self.weaponmodel = "progs/v_shot2.mdl";
  777.         self.weaponframe = 0;
  778.         self.items = self.items | IT_SHELLS;
  779.     }
  780.     else if (self.weapon == IT_NAILGUN)
  781.     {
  782.         self.currentammo = self.ammo_nails;
  783.         self.weaponmodel = "progs/v_nail.mdl";
  784.         self.weaponframe = 0;
  785.         self.items = self.items | IT_NAILS;
  786.     }
  787.     else if (self.weapon == IT_SUPER_NAILGUN)
  788.     {
  789.         self.currentammo = self.ammo_nails;
  790.         self.weaponmodel = "progs/v_nail2.mdl";
  791.         self.weaponframe = 0;
  792.         self.items = self.items | IT_NAILS;
  793.     }
  794.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  795.     {
  796.         self.currentammo = self.ammo_rockets;
  797.         self.weaponmodel = "progs/v_rock.mdl";
  798.         self.weaponframe = 0;
  799.         self.items = self.items | IT_ROCKETS;
  800.     }
  801.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  802.     {
  803.         self.currentammo = self.ammo_rockets;
  804.         self.weaponmodel = "progs/v_rock2.mdl";
  805.         self.weaponframe = 0;
  806.         self.items = self.items | IT_ROCKETS;
  807.     }
  808.     else if (self.weapon == IT_LIGHTNING)
  809.     {
  810.         self.currentammo = self.ammo_cells;
  811.         self.weaponmodel = "progs/v_light.mdl";
  812.         self.weaponframe = 0;
  813.         self.items = self.items | IT_CELLS;
  814.     }
  815.     else
  816.     {
  817.         self.currentammo = 0;
  818.         self.weaponmodel = "";
  819.         self.weaponframe = 0;
  820.     }
  821. };
  822.  
  823. float() W_BestWeapon =
  824. {
  825.     local    float    it;
  826.     
  827.     it = self.items;
  828.  
  829.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  830.         return IT_LIGHTNING;
  831.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  832.         return IT_SUPER_NAILGUN;
  833.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  834.         return IT_SUPER_SHOTGUN;
  835.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  836.         return IT_NAILGUN;
  837.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  838.         return IT_SHOTGUN;
  839.         
  840. /*
  841.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  842.         return IT_ROCKET_LAUNCHER;
  843.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  844.         return IT_GRENADE_LAUNCHER;
  845.  
  846. */
  847.  
  848.     return IT_AXE;
  849. };
  850.  
  851. float() W_CheckNoAmmo =
  852. {
  853.     if (self.currentammo > 0)
  854.         return TRUE;
  855.  
  856.     if (self.weapon == IT_AXE)
  857.         return TRUE;
  858.     
  859.     self.weapon = W_BestWeapon ();
  860.  
  861.     W_SetCurrentAmmo ();
  862.     
  863. // drop the weapon down
  864.     return FALSE;
  865. };
  866.  
  867. /*
  868. ============
  869. W_Attack
  870.  
  871. An attack impulse can be triggered now
  872. ============
  873. */
  874. void()    player_axe1;
  875. void()    player_axeb1;
  876. void()    player_axec1;
  877. void()    player_axed1;
  878. void()    player_shot1;
  879. void()    player_nail1;
  880. void()    player_light1;
  881. void()    player_rocket1;
  882.  
  883. void() W_Attack =
  884. {
  885.     local    float    r;
  886.  
  887.     if (!W_CheckNoAmmo ())
  888.         return;
  889.  
  890.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  891.     self.show_hostile = time + 1;    // wake monsters up
  892.  
  893.     if (self.weapon == IT_AXE)
  894.     {
  895.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  896.         r = random();
  897.         if (r < 0.25)
  898.             player_axe1 ();
  899.         else if (r<0.5)
  900.             player_axeb1 ();
  901.         else if (r<0.75)
  902.             player_axec1 ();
  903.         else
  904.             player_axed1 ();
  905.         self.attack_finished = time + 0.5;
  906.     }
  907.     else if (self.weapon == IT_SHOTGUN)
  908.     {
  909.         player_shot1 ();
  910.         W_FireShotgun ();
  911.         self.attack_finished = time + 0.5;
  912.     }
  913.     else if (self.weapon == IT_SUPER_SHOTGUN)
  914.     {
  915.         player_shot1 ();
  916.         W_FireSuperShotgun ();
  917.         self.attack_finished = time + 0.7;
  918.     }
  919.     else if (self.weapon == IT_NAILGUN)
  920.     {
  921.         player_nail1 ();
  922.     }
  923.     else if (self.weapon == IT_SUPER_NAILGUN)
  924.     {
  925.         player_nail1 ();
  926.     }
  927.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  928.     {
  929.         player_rocket1();
  930.         W_FireGrenade();
  931.         self.attack_finished = time + 0.6;
  932.     }
  933.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  934.     {
  935.         player_rocket1();
  936.         W_FireRocket();
  937.         self.attack_finished = time + 0.8;
  938.     }
  939.     else if (self.weapon == IT_LIGHTNING)
  940.     {
  941.         player_light1();
  942.         self.attack_finished = time + 0.1;
  943.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  944.     }
  945. };
  946.  
  947. /*
  948. ============
  949. W_ChangeWeapon
  950.  
  951. ============
  952. */
  953. void() W_ChangeWeapon =
  954. {
  955.     local    float    it, am, fl;
  956.     
  957.     it = self.items;
  958.     am = 0;
  959.     
  960.     if (self.impulse == 1)
  961.     {
  962.         fl = IT_AXE;
  963.     }
  964.     else if (self.impulse == 2)
  965.     {
  966.         fl = IT_SHOTGUN;
  967.         if (self.ammo_shells < 1)
  968.             am = 1;
  969.     }
  970.     else if (self.impulse == 3)
  971.     {
  972.         fl = IT_SUPER_SHOTGUN;
  973.         if (self.ammo_shells < 2)
  974.             am = 1;
  975.     }        
  976.     else if (self.impulse == 4)
  977.     {
  978.         fl = IT_NAILGUN;
  979.         if (self.ammo_nails < 1)
  980.             am = 1;
  981.     }
  982.     else if (self.impulse == 5)
  983.     {
  984.         fl = IT_SUPER_NAILGUN;
  985.         if (self.ammo_nails < 2)
  986.             am = 1;
  987.     }
  988.     else if (self.impulse == 6)
  989.     {
  990.         fl = IT_GRENADE_LAUNCHER;
  991.         if (self.ammo_rockets < 1)
  992.             am = 1;
  993.     }
  994.     else if (self.impulse == 7)
  995.     {
  996.         fl = IT_ROCKET_LAUNCHER;
  997.         if (self.ammo_rockets < 1)
  998.             am = 1;
  999.     }
  1000.     else if (self.impulse == 8)
  1001.     {
  1002.         fl = IT_LIGHTNING;
  1003.         if (self.ammo_cells < 1)
  1004.             am = 1;
  1005.     }
  1006.  
  1007.     self.impulse = 0;
  1008.     
  1009.     if (!(self.items & fl))
  1010.     {    // don't have the weapon or the ammo
  1011.         sprint (self, "no weapon.\n");
  1012.         return;
  1013.     }
  1014.     
  1015.     if (am)
  1016.     {    // don't have the ammo
  1017.         sprint (self, "not enough ammo.\n");
  1018.         return;
  1019.     }
  1020.  
  1021. //
  1022. // set weapon, set ammo
  1023. //
  1024.     self.weapon = fl;        
  1025.     W_SetCurrentAmmo ();
  1026. };
  1027.  
  1028. /*
  1029. ============
  1030. CheatCommand
  1031. ============
  1032. */
  1033. void() CheatCommand =
  1034. {
  1035.     if (deathmatch || coop)
  1036.         return;
  1037.  
  1038.     self.ammo_rockets = 100;
  1039.     self.ammo_nails = 200;
  1040.     self.ammo_shells = 100;
  1041.     self.items = self.items | 
  1042.         IT_AXE |
  1043.         IT_SHOTGUN |
  1044.         IT_SUPER_SHOTGUN |
  1045.         IT_NAILGUN |
  1046.         IT_SUPER_NAILGUN |
  1047.         IT_GRENADE_LAUNCHER |
  1048.         IT_ROCKET_LAUNCHER |
  1049.         IT_KEY1 | IT_KEY2;
  1050.  
  1051.     self.ammo_cells = 200;
  1052.     self.items = self.items | IT_LIGHTNING;
  1053.  
  1054.     self.weapon = IT_ROCKET_LAUNCHER;
  1055.     self.impulse = 0;
  1056.     W_SetCurrentAmmo ();
  1057. };
  1058.  
  1059. /*
  1060. ============
  1061. CycleWeaponCommand
  1062.  
  1063. Go to the next weapon with ammo
  1064. ============
  1065. */
  1066. void() CycleWeaponCommand =
  1067. {
  1068.     local    float    it, am;
  1069.     
  1070.     it = self.items;
  1071.     self.impulse = 0;
  1072.     
  1073.     while (1)
  1074.     {
  1075.         am = 0;
  1076.  
  1077.         if (self.weapon == IT_LIGHTNING)
  1078.         {
  1079.             self.weapon = IT_AXE;
  1080.         }
  1081.         else if (self.weapon == IT_AXE)
  1082.         {
  1083.             self.weapon = IT_SHOTGUN;
  1084.             if (self.ammo_shells < 1)
  1085.                 am = 1;
  1086.         }
  1087.         else if (self.weapon == IT_SHOTGUN)
  1088.         {
  1089.             self.weapon = IT_SUPER_SHOTGUN;
  1090.             if (self.ammo_shells < 2)
  1091.                 am = 1;
  1092.                 }        
  1093.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1094.         {
  1095.             self.weapon = IT_NAILGUN;
  1096.             if (self.ammo_nails < 1)
  1097.                 am = 1;
  1098.         }
  1099.         else if (self.weapon == IT_NAILGUN)
  1100.         {
  1101.             self.weapon = IT_SUPER_NAILGUN;
  1102.             if (self.ammo_nails < 2)
  1103.                 am = 1;
  1104.         }
  1105.         else if (self.weapon == IT_SUPER_NAILGUN)
  1106.         {
  1107.             self.weapon = IT_GRENADE_LAUNCHER;
  1108.             if (self.ammo_rockets < 1)
  1109.                 am = 1;
  1110.         }
  1111.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1112.         {
  1113.             self.weapon = IT_ROCKET_LAUNCHER;
  1114.             if (self.ammo_rockets < 1)
  1115.                 am = 1;
  1116.         }
  1117.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1118.         {
  1119.             self.weapon = IT_LIGHTNING;
  1120.             if (self.ammo_cells < 1)
  1121.                 am = 1;
  1122.         }
  1123.     
  1124.         if ( (self.items & self.weapon) && am == 0)
  1125.         {
  1126.             W_SetCurrentAmmo ();
  1127.             return;
  1128.         }
  1129.     }
  1130.  
  1131. };
  1132.  
  1133. /*
  1134. ============
  1135. ServerflagsCommand
  1136.  
  1137. Just for development
  1138. ============
  1139. */
  1140. void() ServerflagsCommand =
  1141. {
  1142.     serverflags = serverflags * 2 + 1;
  1143. };
  1144.  
  1145. void() QuadCheat =
  1146. {
  1147.     if (deathmatch || coop)
  1148.         return;
  1149.     self.super_time = 1;
  1150.     self.super_damage_finished = time + 30;
  1151.     self.items = self.items | IT_QUAD;
  1152.     dprint ("quad cheat\n");
  1153. };
  1154.  
  1155. /*
  1156. ============
  1157. ImpulseCommands
  1158.  
  1159. ============
  1160. */
  1161. void() ImpulseCommands =
  1162. {
  1163.         local entity scorefind, botview;
  1164.         local string fragcount;
  1165.  
  1166. // New code
  1167.     CheckSecondaryImpulseCommands();
  1168.         /*
  1169.         if (self.impulse == 102)
  1170.         {
  1171.                 scorefind = find(world, classname, "bot");
  1172.                 fragcount = ftos(scorefind.frags);
  1173.                 bprint(ftos(bots));
  1174.                 bprint(scorefind.netname);
  1175.                 bprint(" has ");
  1176.                 bprint(fragcount);
  1177.                 bprint(" frags\n");
  1178.         }*/
  1179.         /*if (self.impulse == 103) // view from bot
  1180.         {  
  1181.                 botview = find(world, classname, "bot");
  1182.                 msg_entity = self;
  1183.                 WriteByte(MSG_ONE, SVC_SETVIEWPORT);
  1184.                 WriteByte(MSG_ONE, SVC_SETVIEWANGLES);
  1185.                 WriteEntity(MSG_ONE, botview);
  1186.         }*/  
  1187.         if (self.impulse == 104) // upper skin
  1188.         {
  1189.                 self.skin = self.skin + 1;
  1190.         }
  1191.         if (self.impulse == 105) // lower skin
  1192.         {
  1193.                 self.skin = self.skin - 1;
  1194.         }
  1195.         if (self.impulse >= 1 && self.impulse <= 8)
  1196.         W_ChangeWeapon ();
  1197.  
  1198.     if (self.impulse == 9)
  1199.         CheatCommand ();
  1200.     if (self.impulse == 10)
  1201.         CycleWeaponCommand ();
  1202.     if (self.impulse == 11)
  1203.         ServerflagsCommand ();
  1204.  
  1205.     if (self.impulse == 255)
  1206.         QuadCheat ();
  1207.         
  1208.     self.impulse = 0;
  1209. };
  1210.  
  1211. /*
  1212. ============
  1213. W_WeaponFrame
  1214.  
  1215. Called every frame so impulse events can be handled as well as possible
  1216. ============
  1217. */
  1218. void() W_WeaponFrame =
  1219. {
  1220.     if (time < self.attack_finished)
  1221.         return;
  1222.  
  1223.     ImpulseCommands ();
  1224.     
  1225. // check for attack
  1226.     if (self.button0)
  1227.     {
  1228.         SuperDamageSound ();
  1229.         W_Attack ();
  1230.     }
  1231. };
  1232.  
  1233. /*
  1234. ========
  1235. SuperDamageSound
  1236.  
  1237. Plays sound if needed
  1238. ========
  1239. */
  1240. void() SuperDamageSound =
  1241. {
  1242.     if (self.super_damage_finished > time)
  1243.     {
  1244.         if (self.super_sound < time)
  1245.         {
  1246.             self.super_sound = time + 1;
  1247.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1248.         }
  1249.     }
  1250.     return;
  1251. };
  1252.  
  1253.  
  1254.